function ErrorCalculatorModSTHarmonic
format long e;

modx50=load('modx50.out');
modx100=load('modx100.out');
modx150=load('modx150.out');
modx200=load('modx200.out');
modx250=load('modx250.out');
modx300=load('modx300.out');
modx350=load('modx350.out');
modx400=load('modx400.out');
modx450=load('modx450.out');
modx500=load('modx500.out');
modx550=load('modx550.out');
modx600=load('modx600.out');

datax50=[modx50(:,1) -0.239*modx50(:,2)];
datax100=[modx100(:,1) -0.239*modx100(:,2)];
datax150=[modx150(:,1) -0.239*modx150(:,2)];
datax200=[modx200(:,1) -0.239*modx200(:,2)];
datax250=[modx250(:,1) -0.239*modx250(:,2)];
datax300=[modx300(:,1) -0.239*modx300(:,2)];
datax350=[modx350(:,1) -0.239*modx350(:,2)];
datax400=[modx400(:,1) -0.239*modx400(:,2)];
datax450=[modx450(:,1) -0.239*modx450(:,2)];
datax500=[modx500(:,1) -0.239*modx500(:,2)];
datax550=[modx550(:,1) -0.239*modx550(:,2)];
datax600=[modx600(:,1) -0.239*modx600(:,2)];

NNN=length(modx50);
fftx50=fft(datax50(:,2))/NNN;
fftx100=fft(datax100(:,2))/NNN;
fftx150=fft(datax150(:,2))/NNN;
fftx200=fft(datax200(:,2))/NNN;
fftx250=fft(datax250(:,2))/NNN;
fftx300=fft(datax300(:,2))/NNN;
fftx350=fft(datax350(:,2))/NNN;
fftx400=fft(datax400(:,2))/NNN;
fftx450=fft(datax450(:,2))/NNN;
fftx500=fft(datax500(:,2))/NNN;
fftx550=fft(datax550(:,2))/NNN;
fftx600=fft(datax600(:,2))/NNN;
fftxAll=[fftx50,fftx100,fftx150,fftx200,fftx250,fftx300,fftx350,fftx400,fftx450,fftx500,fftx550,fftx600]';

ZeroModeLoc=163;
NumModes=41;
% The following k0 value includes surface tension.
k0=1.52951590372984113;
epsilon=2*k0*abs(fftx50(ZeroModeLoc));

ExptGauges=abs(fftxAll(:,ZeroModeLoc-NumModes:ZeroModeLoc+NumModes));
[MMM,JJJ]=size(ExptGauges);

NLSSTHarmonicAlldata=epsilon/k0*load('NLSSTHarmonicAlldata.out');
dNLSSTHarmonicAlldata=epsilon/k0*load('dNLSSTHarmonicAlldata.out');
DystheSTHarmonicAlldata=epsilon/k0*load('DystheSTHarmonicAlldata.out');
vDystheSTHarmonicAlldata=epsilon/k0*load('vDystheSTHarmonicAlldata.out');
dGTSTHarmonicAlldata=epsilon/k0*load('dGTSTHarmonicAlldata.out');
NLSSTHarmonicGauges=NLSSTHarmonicAlldata(1:500:5501,:);
dNLSSTHarmonicGauges=dNLSSTHarmonicAlldata(1:500:5501,:);
DystheSTHarmonicGauges=DystheSTHarmonicAlldata(1:500:5501,:);
vDystheSTHarmonicGauges=vDystheSTHarmonicAlldata(1:500:5501,:);
dGTSTHarmonicGauges=dGTSTHarmonicAlldata(1:500:5501,:);

HannahNLSSTHarmonicError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-NLSSTHarmonicGauges').^2)./sum((abs(ExptGauges')).^2))
HannahdNLSSTHarmonicError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-dNLSSTHarmonicGauges').^2)./sum((abs(ExptGauges')).^2))
HannahDystheSTHarmonicError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-DystheSTHarmonicGauges').^2)./sum((abs(ExptGauges')).^2))
HannahvDystheSTHarmonicError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-vDystheSTHarmonicGauges').^2)./sum((abs(ExptGauges')).^2))
HannahdGTSTHarmonicError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-dGTSTHarmonicGauges').^2)./sum((abs(ExptGauges')).^2))

u1p=4;
u2p=8;
u3p=12;
l1m=4;
l2m=8;
l3m=12;

a0s=abs(fftxAll(:,ZeroModeLoc));
an1s=abs(fftxAll(:,ZeroModeLoc-l1m));
a1s=abs(fftxAll(:,ZeroModeLoc+u1p));
an2s=abs(fftxAll(:,ZeroModeLoc-l2m));
a2s=abs(fftxAll(:,ZeroModeLoc+u2p));
an3s=abs(fftxAll(:,ZeroModeLoc-l3m));
a3s=abs(fftxAll(:,ZeroModeLoc+u3p));

carrier=(JJJ+1)/2;
u1=carrier+u1p;
u2=carrier+u2p;
u3=carrier+u3p;
l1=carrier-l1m;
l2=carrier-l2m;
l3=carrier-l3m;

NLSSTHarmoniccarrier=NLSSTHarmonicAlldata(1:100:end,carrier);
dNLSSTHarmoniccarrier=dNLSSTHarmonicAlldata(1:100:end,carrier);
DystheSTHarmoniccarrier=DystheSTHarmonicAlldata(1:100:end,carrier);
vDystheSTHarmoniccarrier=vDystheSTHarmonicAlldata(1:100:end,carrier);
dGTSTHarmoniccarrier=dGTSTHarmonicAlldata(1:100:end,carrier);
NLSu1=NLSSTHarmonicAlldata(1:100:end,u1);
dNLSu1=dNLSSTHarmonicAlldata(1:100:end,u1);
Dystheu1=DystheSTHarmonicAlldata(1:100:end,u1);
vDystheu1=vDystheSTHarmonicAlldata(1:100:end,u1);
dGTSTHarmonicu1=dGTSTHarmonicAlldata(1:100:end,u1);
NLSu2=NLSSTHarmonicAlldata(1:100:end,u2);
dNLSu2=dNLSSTHarmonicAlldata(1:100:end,u2);
Dystheu2=DystheSTHarmonicAlldata(1:100:end,u2);
vDystheu2=vDystheSTHarmonicAlldata(1:100:end,u2);
dGTSTHarmonicu2=dGTSTHarmonicAlldata(1:100:end,u2);
NLSu3=NLSSTHarmonicAlldata(1:100:end,u3);
dNLSu3=dNLSSTHarmonicAlldata(1:100:end,u3);
Dystheu3=DystheSTHarmonicAlldata(1:100:end,u3);
vDystheu3=vDystheSTHarmonicAlldata(1:100:end,u3);
dGTSTHarmonicu3=dGTSTHarmonicAlldata(1:100:end,u3);

NLSl1=NLSSTHarmonicAlldata(1:100:end,l1);
dNLSl1=dNLSSTHarmonicAlldata(1:100:end,l1);
Dysthel1=DystheSTHarmonicAlldata(1:100:end,l1);
vDysthel1=vDystheSTHarmonicAlldata(1:100:end,l1);
dGTSTHarmonicl1=dGTSTHarmonicAlldata(1:100:end,l1);
NLSl2=NLSSTHarmonicAlldata(1:100:end,l2);
dNLSl2=dNLSSTHarmonicAlldata(1:100:end,l2);
Dysthel2=DystheSTHarmonicAlldata(1:100:end,l2);
vDysthel2=vDystheSTHarmonicAlldata(1:100:end,l2);
dGTSTHarmonicl2=dGTSTHarmonicAlldata(1:100:end,l2);
NLSl3=NLSSTHarmonicAlldata(1:100:end,l3);
dNLSl3=dNLSSTHarmonicAlldata(1:100:end,l3);
Dysthel3=DystheSTHarmonicAlldata(1:100:end,l3);
vDysthel3=vDystheSTHarmonicAlldata(1:100:end,l3);
dGTSTHarmonicl3=dGTSTHarmonicAlldata(1:100:end,l3);

positions=[0,50,100,150,200,250,300,350,400,450,500,550]';
x=0:1/10:5500/10;
x=x(1:100:end);

figure(6)
subplot(4,2,[1,2])
hold off
scatter(positions,a0s,'filled','k')
hold on
plot(x,NLSSTHarmoniccarrier,'k')
plot(x,DystheSTHarmoniccarrier,'k--')
l=legend('data','NLS','Dysthe','Location','SouthWest','Orientation','horizontal');
l.NumColumns=2;
ylabel('$|a_0|$','Interpreter','Latex')
title('Expt A Second Harmonic')
axis tight
subplot(4,2,3)
hold off
scatter(positions,an1s,'filled','k')
hold on
plot(x,NLSl1,'k')
plot(x,Dysthel1,'k--')
ylabel('$|a_{-4}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.004])
subplot(4,2,4)
hold off
scatter(positions,a1s,'filled','k')
hold on
plot(x,NLSu1,'k')
plot(x,Dystheu1,'k--')
ylabel('$|a_3|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.004])
subplot(4,2,5)
hold off
scatter(positions,an2s,'filled','k')
hold on
plot(x,NLSl2,'k')
plot(x,Dysthel2,'k--')
ylabel('$|a_{-8}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.0025])
subplot(4,2,6)
hold off
scatter(positions,a2s,'filled','k')
hold on
plot(x,NLSu2,'k')
plot(x,Dystheu2,'k--')
ylabel('$|a_8|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.0025])
subplot(4,2,7)
hold off
scatter(positions,an3s,'filled','k')
hold on
plot(x,NLSl3,'k')
plot(x,Dysthel3,'k--')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{-12}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.001])
subplot(4,2,8)
hold off
scatter(positions,a3s,'filled','k')
hold on
plot(x,NLSu3,'k')
plot(x,Dystheu3,'k--')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{12}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.001])



figure(66)
subplot(4,2,[1,2])
hold off
scatter(positions,a0s,'filled','k')
hold on
plot(x,dNLSSTHarmoniccarrier,'k')
plot(x,vDystheSTHarmoniccarrier,'k--')
plot(x,dGTSTHarmoniccarrier,'k-.')
l=legend('data','dNLS','vDysthe','dGT','Location','NorthEast','Orientation','horizontal');
l.NumColumns=2;
ylabel('$|a_0|$','Interpreter','Latex')
title('Expt A Second Harmonic')
axis tight
subplot(4,2,3)
hold off
scatter(positions,an1s,'filled','k')
hold on
plot(x,dNLSl1,'k')
plot(x,vDysthel1,'k--')
plot(x,dGTSTHarmonicl1,'k-.')
ylabel('$|a_{-4}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.004])
subplot(4,2,4)
hold off
scatter(positions,a1s,'filled','k')
hold on
plot(x,dNLSu1,'k')
plot(x,vDystheu1,'k--')
plot(x,dGTSTHarmonicu1,'k-.')
ylabel('$|a_4|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.004])
subplot(4,2,5)
hold off
scatter(positions,an2s,'filled','k')
hold on
plot(x,dNLSl2,'k')
plot(x,vDysthel2,'k--')
plot(x,dGTSTHarmonicl2,'k-.')
ylabel('$|a_{-8}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.0025])
subplot(4,2,6)
hold off
scatter(positions,a2s,'filled','k')
hold on
plot(x,dNLSu2,'k')
plot(x,vDystheu2,'k--')
plot(x,dGTSTHarmonicu2,'k-.')
ylabel('$|a_8|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.0025])
subplot(4,2,7)
hold off
scatter(positions,an3s,'filled','k')
hold on
plot(x,dNLSl3,'k')
plot(x,vDysthel3,'k--')
plot(x,dGTSTHarmonicl3,'k-.')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{-12}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.001])
subplot(4,2,8)
hold off
scatter(positions,a3s,'filled','k')
hold on
plot(x,dNLSu3,'k')
plot(x,vDystheu3,'k--')
plot(x,dGTSTHarmonicu3,'k-.')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{12}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.001])
